<?php

namespace JLPay\Models\Clearing;

/**
 * 文件上传请求
 */
class FileUploadRequest
{
    /**
     * API前缀
     */
    public const API_PREFIX = '/base/file/upload';
    
    /**
     * API URI
     */
    public const API_URI = '/video';

    protected ?string $fileName = null;
    protected ?string $alg = null;
    protected ?string $file = null;

    /**
     * 设置文件名
     *
     * @param string $fileName
     * @return self
     */
    public function setFileName(string $fileName): self
    {
        $this->fileName = $fileName;
        return $this;
    }

    /**
     * 设置算法类型
     *
     * @param string $alg
     * @return self
     */
    public function setAlg(string $alg): self
    {
        $this->alg = $alg;
        return $this;
    }

    /**
     * 设置文件内容
     *
     * @param string $file
     * @return self
     */
    public function setFile(string $file): self
    {
        $this->file = $file;
        return $this;
    }

    /**
     * 获取文件名
     *
     * @return string|null
     */
    public function getFileName(): ?string
    {
        return $this->fileName;
    }

    /**
     * 获取算法类型
     *
     * @return string|null
     */
    public function getAlg(): ?string
    {
        return $this->alg;
    }

    /**
     * 获取文件内容
     *
     * @return string|null
     */
    public function getFile(): ?string
    {
        return $this->file;
    }

    /**
     * 将请求对象转换为数组，过滤掉值为null的字段
     *
     * @return array
     */
    public function toArray(): array
    {
        $result = [];
        
        if ($this->fileName !== null) {
            $result['file_name'] = $this->fileName;
        }
        
        if ($this->alg !== null) {
            $result['alg'] = $this->alg;
        }
        
        if ($this->file !== null) {
            $result['file'] = $this->file;
        }
        
        return $result;
    }

    /**
     * 获取multipart请求的元数据数组
     *
     * @return array
     */
    public function getMetaArray(): array
    {
        return [
            'filename' => $this->fileName,
            'alg' => $this->alg
        ];
    }
} 